package main

import (
	"example/application/blockchain"
	"example/application/controller"
	"net/http"

	"github.com/gin-gonic/gin"
)

func setRouter() *gin.Engine {
	router := gin.New()
	router.Use(controller.CORS)
	router.Use(controller.FixVueRouter)

	router.POST("/createCompany", controller.CreateCompany)
	router.GET("/getCompany", controller.GetCompany)
	router.POST("/newTransaction", controller.NewTransaction)
	router.POST("/confirmTransaction", controller.ConfirmTransaction)
	router.POST("/applyPayForAnother", controller.ApplyPayForAnother)
	router.POST("/payTransaction", controller.PayTransaction)
	router.POST("/affirmPay", controller.AffirmPay)
	router.POST("/refusePayTransaction", controller.RefusePayTransaction)
	router.POST("/updateShipmentInfo", controller.UpdateShipmentInfo)
	router.POST("/verifyShipmentInfo", controller.VerifyShipmentInfo)
	router.POST("/repayTransaction", controller.RepayTransaction)
	router.POST("/verifyRepay", controller.VerifyRepay)
	router.POST("/autoRepay", controller.AutoRepay)
	router.GET("/getTrByBuyer", controller.GetTrByBuyer)
	router.GET("/getTransactions", controller.GetTransactions)
	router.GET("/getTransactionHistory", controller.GetTransactionHistory)

	router.StaticFS("/web", http.Dir("./public"))
	return router
}

func main() {
	blockchain.Init()

	router := setRouter()

	err := router.Run(":8080")
	if err != nil {
		panic(err.Error())
	}
}
